package net.vistiyos.activities;

import net.vistiyos.R;
import net.vistiyos.util.FilesTubeAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener{
	
	private EditText query;
	private FilesTubeAdapter fta;
	
	 @Override
	  public void onCreate(Bundle icicle) {
	    super.onCreate(icicle);
	    setContentView(R.layout.principal);
	    Button search=(Button) findViewById(R.id.search);
	    search.setOnClickListener(this);
	    query=(EditText)findViewById(R.id.query);
	    fta=new FilesTubeAdapter(this);
	    fta.open();
	  }

	@Override
	public void onClick(View v) {
		if(!fta.exists(query.getText().toString()))
			fta.createTodo(query.getText().toString());
		String query=this.query.getText().toString();
		String[] palabras=query.split(" ");
		StringBuilder sb=new StringBuilder();
		for(String palabra:palabras){
			sb.append(palabra+",");
		}
		sb.deleteCharAt(sb.toString().length()-1);
		Intent i=new Intent(this,List.class);
		i.putExtra("query",sb.toString());
		startActivity(i);
	}
	  
	  
}